<?php

	include ('../Config/conn.php'); 
	include ('../Model/proposta.class.php'); 

	$exemplares_interessado = array();
		
	$id_exemplar_dono = isset($_POST['id_exemplar_dono']) ? $_POST['id_exemplar_dono'] : '0';
	$exemplares_interessado = isset($_POST['exemplares_interessado']) ? $_POST['exemplares_interessado'] : null;	
	$cd_formatroca = isset($_POST['cd_formatroca']) ? $_POST['cd_formatroca'] : '0';

	$novaProposta = new Proposta($db, 0, 0, $cd_formatroca, '1', ' ');
	$novaProposta->insereProposta($db, $id_exemplar_dono, $exemplares_interessado);	

		
	$nome_interessado = "";
	$email_interessado = "";
	$email_dono = "";
	$nome_dono = "";
	
	$idUser = $novaProposta->cdUsuario_dono;
	
	$result = $db->query("SELECT usu.ds_email,
								 usu.nm_usuario
							FROM Usuario usu
						   WHERE usu.cd_usuario = '$idUser';",
									PDO::FETCH_ASSOC);
	
	if ($result->rowCount() > 0) {
	
		$teste = $result->fetch();
		
		$email_dono = $teste['ds_email'];
		$nome_dono = $teste['nm_usuario'];
		$result->closeCursor();

	}
	
	$idUser = $novaProposta->cdUsuario_interessado;
		
	$result = $db->query("SELECT usu.ds_email,
								 usu.nm_usuario
							FROM Usuario usu
						   WHERE usu.cd_usuario = '$idUser';",
									PDO::FETCH_ASSOC);
	
	if ($result->rowCount() > 0) {
	
		$teste = $result->fetch();
		
		$nome_interessado = $teste['nm_usuario'];
		$email_interessado = $teste['ds_email'];
		$result->closeCursor();

	}

	/*
	if ($result->rowCount() > 0) {
		
		while($exemplar = $result->fetch()){

			$nome_interessado = $exemplar['nm_usuario'];
			$email_interessado = $exemplar['ds_email'];
		}
		
		$result->closeCursor();	
	}*/
	
	include ('../Config/destruct.php');
	
	include('../Controller/enviar_email_usuario_recebe_proposta.php')

?>